﻿using System;
using System.Collections.Generic;
using AI;
using UnityEngine;

// Token: 0x020001F3 RID: 499
public abstract class DecisionMaker
{
	// Token: 0x06000AAD RID: 2733 RVA: 0x0005B60F File Offset: 0x0005980F
	protected DecisionMaker(Humanoid entity)
	{
		this.entity = entity;
		this.ai = entity.ai;
	}

	// Token: 0x06000AAE RID: 2734
	public abstract void Execute();

	// Token: 0x06000AAF RID: 2735 RVA: 0x0005B62C File Offset: 0x0005982C
	public LuaBehavior ChooseBehavior(List<IBehavior> behaviors)
	{
		if (behaviors == null || behaviors.Count == 0)
		{
			return null;
		}
		Dictionary<LuaBehavior, float> dictionary = new Dictionary<LuaBehavior, float>();
		float num = 0f;
		foreach (IBehavior behavior in behaviors)
		{
			LuaBehavior luaBehavior = (LuaBehavior)behavior;
			float num2 = 0f;
			if (luaBehavior.scores != null)
			{
				foreach (BehaviorScore score in luaBehavior.scores)
				{
					num2 += this.EvaluateScore(score);
				}
			}
			num2 = Mathf.Max(num2, 0f);
			dictionary.Add(luaBehavior, num2);
			num += num2;
		}
		if (num == 0f)
		{
			return (LuaBehavior)behaviors[UnityEngine.Random.Range(0, behaviors.Count)];
		}
		float num3 = UnityEngine.Random.value * num;
		float num4 = 0f;
		foreach (IBehavior behavior2 in behaviors)
		{
			LuaBehavior luaBehavior2 = (LuaBehavior)behavior2;
			num4 += dictionary[luaBehavior2];
			if (num4 > num3)
			{
				return luaBehavior2;
			}
		}
		return null;
	}

	// Token: 0x06000AB0 RID: 2736 RVA: 0x0005B7C0 File Offset: 0x000599C0
	private float EvaluateScore(BehaviorScore score)
	{
		float num = 1f;
		switch (score.type)
		{
		case ScoreType.normal:
			num = this.ai.mentalState.normal;
			break;
		case ScoreType.afraid:
			num = this.ai.mentalState.fear;
			break;
		case ScoreType.curious:
			num = this.ai.mentalState.curiosity;
			break;
		case ScoreType.hostile:
			num = this.ai.mentalState.hostile;
			break;
		}
		return num * score.value;
	}

	// Token: 0x06000AB1 RID: 2737 RVA: 0x0005B858 File Offset: 0x00059A58
	protected Vector3 getRandomPoint()
	{
		Vector2 vector = UnityEngine.Random.insideUnitCircle * this.entity.Scale * 20f;
		return this.entity.transform.position + new Vector3(vector.x, 0f, vector.y);
	}

	// Token: 0x04000FC7 RID: 4039
	protected AIController ai;

	// Token: 0x04000FC8 RID: 4040
	protected Humanoid entity;
}
